﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace _1stVATCWin
{
    public partial class HD_ADD : Form
    {
        public HD_ADD()
        {
            InitializeComponent();
        }

        private void HD_ADD_Load(object sender, EventArgs e)
        {
            load_IDNCC();
        }

        private void load_IDNCC()
        {
            Config file = new Config(Application.StartupPath + "\\config.ini");
            string connectionString = file.ReadValue("server", "conn");
            SqlConnection conn = new SqlConnection(connectionString);
            string sql = "select * from NHACUNGCAP";
            SqlCommand cmd = new SqlCommand(sql, conn);

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            conn.Open();
            DataSet ds = new DataSet();
            adapter.Fill(ds, "Table NCC");
            DataTable dt = ds.Tables["Table NCC"];

            idncc.DisplayMember = "tenNCC";
            idncc.ValueMember = "IDNCC";
            idncc.DataSource = ds.Tables["Table NCC"].DefaultView;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;

            Config file = new Config(Application.StartupPath + "\\config.ini");
            string connectionString = file.ReadValue("server", "conn");               
            SqlConnection conn = new SqlConnection(connectionString);
            string sql = "insert into HOPDONG(IDhopdong,ngayhopdong,IDNCC,dieukhoan,tonggianhap,xacnhan) values(0,@ngay,@idncc,@dk,0,N'Chưa Xác Nhận')";
            SqlCommand cmd = new SqlCommand(sql, conn);
                             
            cmd.Parameters.AddWithValue("@ngay", dateTimePicker1.Value);
            cmd.Parameters.AddWithValue("@idncc", idncc.SelectedValue);
            cmd.Parameters.AddWithValue("@dk", dkhd.Text);
            conn.Open();  
            cmd.ExecuteNonQuery();
            conn.Close();
        }
    }
}
